//package com.cf.game.stage;
//
//import com.cf.Event;
//import com.cf.core.player.Player;
//import com.cf.core.event.TicketEvent;
//import com.cf.core.stage.HeartBeatStage;
//import com.cf.game.GameContext;
//import com.cf.game.constant.SysConstant;
//import com.cf.game.service.constants.EnumReturnCode;
//import com.cf.game.service.exception.BizException;
//import com.cf.game.service.pojo.H5Game;
//import com.cf.game.service.service.UserInfoService;
//import com.cf.game.service.util.BeanFactoryUtil;
//import com.cf.game.stage.npc.EnumStudentStatue;
//import com.cf.serialize.common.RechargeResponse;
//import com.google.common.collect.Lists;
//import lombok.extern.slf4j.Slf4j;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//
///**
// * game-server-MatchStage
// * 匹配尝尽
// *
// * @author <a href="2428922347@qq.com">Zhu mingming</a>
// * @info
// * @since 2018/5/7 下午 03:00
// */
//@Slf4j
//public class OldMatchStage extends HeartBeatStage {
//
//    private List<Player> matchPlayers = new ArrayList();
//
//    public OldMatchStage(int heartBeatStep, int stageTime, String stageNum) {
//        super(heartBeatStep, stageTime, stageNum);
//    }
//
//    @Override
//    protected void handleEvent(Event event) {
//        //todo 处理别的消息
//        log.info("MatchStage 不应该有别的消息啊");
//    }
//
//    @Override
//    protected void handleTicketEvent(TicketEvent event) {
//        //在MatchStage中，心跳消息用来驱动匹配的节奏
//        List<Player> players = getAndResetMatchPlayers();
//        if (players == null || players.size() <= 0)
//            log.info("当前无用户匹配！【{}】", players.size());
//        List<List<Player>> partitions = Lists.partition(players, SysConstant.partitionNum);
//        partitions.forEach(partition -> {
//            goToGameStage(partition);
//        });
//    }
//
//
//    private void goToGameStage(List<Player> partition) {
//        while (partition.size() < SysConstant.partitionNum) {
//            partition.add(null);
//        }
//        ClassRoom classRoom = new ClassRoom(SysConstant.gameTime, partition.get(0), partition.get(1));
//        BeanFactoryUtil.getBean(ClassRoomManager.class).addRoom(classRoom, Arrays.asList(partition.get(0), partition.get(1)));
//    }
//
//
//    /**
//     * 扣费并加入匹配队列
//     */
//    public void getMatchTicketAndJoinQueue(Player player) {
//        H5Game h5Game = BeanFactoryUtil.getBean(GameContext.class).getH5Game();
//        boolean chargingSuccess = BeanFactoryUtil.getBean(UserInfoService.class).charging(player.getId(), h5Game.getMoney().doubleValue(), h5Game.getName() + "扣费");
//        if (chargingSuccess) {
//            //加入到匹配队列
//            //todo 再一局游戏中，不可以开始新一局游戏，现在是可以的
//            matchPlayers.add(player);
//        } else {
//            player.sendMessage(new RechargeResponse());
//        }
//    }
//
//    private List<Player> getAndResetMatchPlayers() {
//        List<Player> players = matchPlayers;
//        this.matchPlayers = new ArrayList();
//        return players;
//    }
//
//    @Override
//    protected void clean() {
//        throw new BizException(EnumReturnCode.ERROR.getCode(), "当前场景不支持clean方法，调此方法属于异常行为！");
//    }
//
//    @Override
//    public String getStatue() {
//        return EnumStudentStatue.COMMON.getStatue();
//    }
//}
